#ifndef __STREAMER_CURTAIN_PLAY__H__
#define __STREAMER_CURTAIN_PLAY__H__

#include <mutex>
#include "json.h"
#include <string>
#include <vector>
#include <functional>
#include "Thread/Thread.h"
#include "Poller/Timer.h"
#include "StreamComposeMgr.h"
#include "StreamerDownloadOnlineFile.h"
#include "DiskController.h"
#include <atomic>

using namespace std;



namespace Media{

const int StreamerNum = 99;

#define STREAM_ROOT_DIR "/streamer/"
#define DESCRIBE_FILENAME "/describe"

typedef enum{
	LOCAL_STREAMER,
	CLIENT_STREAMER,
	WEB_STREAMER,
} StreamerType;


class StreamerCurtainPlay
{ 
public: 
	static StreamerCurtainPlay* instance();

	bool playStreamerCurtain(StreamerType type = LOCAL_STREAMER, std::string rootPath = "");

	bool stopStreamerCurtain();

	bool getMp4VpnValue(std::string& mp4VpnAddr);

	bool playNextStreamer();

	bool stopUsbcardStreamer();
public:
	StreamerCurtainPlay();
	~StreamerCurtainPlay();
	
private:

	bool StartDynamicStreamer();

	bool StartStaticStreamer();

	bool ChangeStreamerNumAction(int action);

	bool streamerDescribeCheckout(Json::Value& streamerTable, std::string url, std::string fileName);

	bool StreamerTableCheckout(Json::Value curtainTable);
	
    bool updateStreamerPlay();

    bool changeDescribeInfo(std::string url, std::string fileName);

    bool getDownloadUrl(std::vector<std::string>& urls);

    bool compareMd5(std::string filename, const char *md5);


private:
	bool clientSyncCloud(Json::Value describeTable);

private:
    static StreamerCurtainPlay*			        sm_streamercurtainPlayIns;

	static std::mutex 			                sm_insMutex;
	
	bool 										m_streamerPlay = false;
	
	bool										m_streamer = false;

	Json::Value 								m_streamTable;

	mutex 										m_stopstreamLock;

	bool									    m_videoStreamer = false;

	bool										m_streamerThread = false;

	bool 										m_streamerPlayThread = false;

	std::string                                 m_mp4VpnAddr;

	uint16_t                                    m_curPlayIndex = 0;

	Json::Value                                 m_curtainTable;

	mutex                                       m_palyDscribeMutex;

	std::string                                 m_curfilePath;

	std::string                                 m_curfileMd5;
	
	std::string 								m_streamerPath;

	std::string 								m_streamerDescPath;
	
	std::string 								m_rootPath;

    std::thread 								m_syncCloud;

	std::atomic<bool>							m_upload{false};

	std::atomic<bool>							m_uploadThread{false};

};

}//namespace Media

#endif

